//
//  BaseCollectionViewCell.m
//  GoldBook
//
//  Created by wmz on 2021/8/15.
//  Copyright © 2021 wmz. All rights reserved.
//

#import "BaseCollectionViewCell.h"

@implementation BaseCollectionViewCell
+ (instancetype)cellWithCollectionView:(UICollectionView *)collectionView forIndexPath:(NSIndexPath *)indexPath {
    return [self cellWithCollectionView:collectionView forIndexPath:indexPath identifier:nil];
}

+ (instancetype)cellWithCollectionView:(UICollectionView *)collectionView forIndexPath:(NSIndexPath *)indexPath identifier:(NSString *)identifier {
    if (!identifier) {
        identifier = NSStringFromClass(self);
    }
    [collectionView registerClass:self.class forCellWithReuseIdentifier:identifier];
    return [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
}

- (void)commonInit {

    [self hd_setupViews];
    [self hd_bindViewModel];
    [self setNeedsUpdateConstraints];
}

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self commonInit];
    }
    return self;
}

- (void)awakeFromNib{
    [super awakeFromNib];
    [self commonInit];
}

- (void)dealloc {
    [NSNotificationCenter.defaultCenter removeObserver:self];
}

#pragma mark - SAViewProtocol
- (void)hd_bindViewModel {
}

- (void)hd_setupViews {
}

#pragma mark - HDSkeletonLayerLayoutProtocol
- (NSArray<HDSkeletonLayer *> *)skeletonLayoutViews {


    HDSkeletonLayer *circle = [[HDSkeletonLayer alloc] init];

    [circle hd_makeFrameLayout:^(HDFrameLayoutMaker *_Nonnull make) {
        make.right.hd_equalTo(self.width).offset(-15);
        make.height.hd_equalTo(self.height * 0.7);
        make.left.hd_equalTo(15);
        make.top.hd_equalTo(15);
    }];
    circle.skeletonCornerRadius = 8;

    HDSkeletonLayer *r1 = [[HDSkeletonLayer alloc] init];
    [r1 hd_makeFrameLayout:^(HDFrameLayoutMaker *_Nonnull make) {
        make.right.hd_equalTo(self.width).offset(-15);
        make.left.hd_equalTo(15);
        make.top.hd_equalTo(circle.hd_bottom).offset(15);
        make.height.hd_equalTo(26);
    }];
    return @[circle, r1];
}

- (UIColor *)skeletonContainerViewBackgroundColor {
    return UIColor.whiteColor;
}

- (CGFloat)skeletonViewHeight {
    return self.frame.size.height;
}
@end
